package com.example.blog.service;

import com.example.blog.mapper.BlogInfoMapper;
import com.example.blog.mapper.UserInfoMapper;
import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    public UserInfo getInfo(String userName) {
        return userInfoMapper.loginInfoByUserName(userName);
    }
    public UserInfo getInfoById(Integer id){
        return userInfoMapper.getInfoById(id);
    }

    public UserInfo getInfoByBlogId(Integer blogId) {
        BlogInfo blogInfo =  blogInfoMapper.selectBlogInfo(blogId);
        if(blogInfo==null||blogInfo.getUserId()==null){
            log.error("找不到该博客信息或博客作者信息缺失");
            return null;
        }
        return userInfoMapper.getInfoById(blogInfo.getUserId());
    }
}
